<?php

error_reporting(E_ALL);
date_default_timezone_set('Asia/Shanghai');
define('APP_PATH', realpath('..'));
//use Phalcon\Mvc\Application;

try {

    /**
     * Read the configuration
     */
    $config = include APP_PATH . "/app/config/config.php";

    /**
     * Read auto-loader
     */
    include APP_PATH . "/app/config/loader.php";

    /**
     * Read services
     */
    include APP_PATH . "/app/config/services.php";

    //myadd
    require APP_PATH . '/app/common/common.php';
    require APP_PATH . '/app/common/hilog.php';

    //Register an autoloader
    $loader = new \Phalcon\Loader();
    $loader->registerDirs(array(
        '../app/controllers/',
        '../app/models/'
    ))->register();

    //Create a DI
    $di = new Phalcon\DI\FactoryDefault();

    //Setup the view component
    $di->set('view', function () {
        $view = new \Phalcon\Mvc\View();
        $view->setViewsDir('../app/views/');
        return $view;
    });

    //Setup a base URI so that all generated URIs include the "story" folder
    $di->set('url', function () {
        $url = new \Phalcon\Mvc\Url();
        $url->setBaseUri('/');
        return $url;
    });

    //myadd log
    //use Phalcon\Logger\Adapter\File as FileAdapter;
    $di->set('logger', function () use ($config) {
        return new Phalcon\Logger\Adapter\File($config['application']['logsDir'] . date('Y-m-d_H') . ".log");
    });

    //myadd session
    $di->setShared('session', function () {
        $session = new Phalcon\Session\Adapter\Files ();
        $session->start();

        return $session;
    });

    $_SN_ = common::sn();
    /**
     * Handle the request
     */
    $application = new \Phalcon\Mvc\Application($di);
    echo $application->handle()->getContent();

} catch (Exception $e) {
    echo "[Status]" . E_EXCEPTION . "\n";
    echo "[Msg]" . $e->getMessage() . "\n";
    echo "[Trace]" . $e->getTraceAsString() . "\n";

    hilog::error('EX:' . $e->getMessage());
}
